package com.utils.basehelper.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class UTC2LoaclTime {
	public static String SHARE_CLICK_TIMES_KEY = "share_click_user_%s_date_%s_times";
/*	public static void main(String[] args) {
        String key = String.format(SHARE_CLICK_TIMES_KEY, "my", DateUtil.formatString(new Date(), "yyyy-MM-dd"));
        System.out.println(key);
		System.out.println(BigDecimal.valueOf(Double.valueOf("4000")));
		System.out.println(Double.valueOf("4000"));
        long ztime = System.nanoTime();
        System.out.println(ztime);
	}*/
	public static void main(String args[]) throws ParseException {
		System.out.println("0"=="0");
//        UTCToCST("2019-04-23T13:44:33.879902112Z", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
//        String a = utc2Local("2019-04-23T13:44:33.879902112Z", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd HH:mm:ss.SSS");
//        System.out.println(a);
	}

    public static void UTCToCST(String UTCStr, String format) throws ParseException {
        Date date = null;
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        date = sdf.parse(UTCStr);
        System.out.println("UTC时间: " + date);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
        //calendar.getTime() 返回的是Date类型，也可以使用calendar.getTimeInMillis()获取时间戳
        System.out.println("北京时间: " + calendar.getTime());
    }
    
    /**
     * 函数功能描述:UTC时间转本地时间格式
     * @param utcTime UTC时间
     * @param utcTimePatten UTC时间格式
     * @param localTimePatten   本地时间格式
     * @return 本地时间格式的时间
     * eg:utc2Local("2017-06-14 09:37:50.788+08:00", "yyyy-MM-dd HH:mm:ss.SSSXXX", "yyyy-MM-dd HH:mm:ss.SSS")
     */
    public static String utc2Local(String utcTime, String utcTimePatten, String localTimePatten) {
        SimpleDateFormat utcFormater = new SimpleDateFormat(utcTimePatten);
        utcFormater.setTimeZone(TimeZone.getTimeZone("UTC"));//时区定义并进行时间获取
        Date gpsUTCDate = null;
        try {
            gpsUTCDate = utcFormater.parse(utcTime);
        } catch (ParseException e) {
            e.printStackTrace();
            return utcTime;
        }
        SimpleDateFormat localFormater = new SimpleDateFormat(localTimePatten);
        localFormater.setTimeZone(TimeZone.getDefault());
        String localTime = localFormater.format(gpsUTCDate.getTime());
        return localTime;
    }

}
